﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectIndieFarm
{
    public class ComputerItem : IComputerItem
    {
        public string Name { get; set; }
        public BindableProperty<bool> Visible { get; set; } = new();
        public BindableProperty<float> CurrentHours { get; set; } = new();
        public float TotalHours { get; set; }
        public BindableProperty<bool> Finished { get; set; } = new();

        private Func<ComputerItem, bool> mCondition;
        private Action mOnFinish;

        public bool ShowCondition()
        {
            return !Finished.Value && (mCondition == null || mCondition.Invoke(this));
        }

        public void Finish()
        {
            Finished.Value = true;
            mOnFinish?.Invoke();
        }

        #region set method
        public ComputerItem SetName(string name)
        {
            Name = name;
            return this;
        }

        public ComputerItem SetTotalHours(float totalHours)
        {
            TotalHours = totalHours;
            return this;
        }

        public ComputerItem OnFInish(Action onFinish)
        {
            mOnFinish = onFinish;
            return this;
        }

        public ComputerItem ShowCondition(Func<ComputerItem, bool> condition)
        {
            mCondition = condition;
            return this;
        }
        #endregion
    }
}
